//
//  SMSRequestProvider.m
//  SulitLoan
//
//  Created by 虞嘉伟 on 2025/2/26.
//


#import "Item2UserInfoRequestProvider.h"
#import "Item2GetUserInfoRequest.h"
#import "Item2UpdateUserInfoRequest.h"

@implementation Item2UserInfoRequestProvider

// 获取用户信息
+ (void)requestItem2GetUserInfoWithProductID:(NSString *)productId success:(void(^)(NSDictionary *dict))success failure:(void(^)(YTKRequest *request))failure {
    Item2GetUserInfoRequest *request = [Item2GetUserInfoRequest new];
    request.scenery = productId;
#ifdef DEBUG
    //request.scenery = @"2";
#endif
    [request startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        NSDictionary *dict = request.responseObject;
        if (![dict isKindOfClass:NSDictionary.class]) {
            !failure ?: failure(request);
            return;
        }
        if ([dict[@"weeps"] intValue] == 0) {
            // 成功
            !success ?: success(dict[@"bounding"]);
        } else {
            !failure ?: failure(request);
        }
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        !failure ?: failure(request);
    }];
}

// 保存用户信息
+ (void)requestUpdateUserInfoWithProductId:(NSString *)productId
                                      info:(NSDictionary *)info
                                   success:(void(^)(NSDictionary *dict))success
                                   failure:(void(^)(YTKRequest *request))failure {
    Item2UpdateUserInfoRequest *request = [Item2UpdateUserInfoRequest new];
    request.scenery = productId;
    request.info = info;
#ifdef DEBUG
//    request.scenery = @"2";
#endif
    [request startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        NSDictionary *dict = request.responseObject;
        if (![dict isKindOfClass:NSDictionary.class]) {
            !failure ?: failure(request);
            return;
        }
        if ([dict[@"weeps"] intValue] == 0) {
            // 成功
            !success ?: success(dict[@"bounding"]);
        } else {
            !failure ?: failure(request);
        }
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        !failure ?: failure(request);
    }];
}


@end
